# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Hyacinthe Cartiaux <hyacinthe.cartiaux@free.fr>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: tobias <tobias@archlinux.org>
# Contributor: Sarah Hay <sarahhay@mb.sympatico.ca>
# Contributor: Mark Pustjens <pustjens@dds.nl>

pkgname=xpdf
pkgver=4.04
pkgrel=2
pkgdesc='Viewer for Portable Document Format (PDF) files'
url='https://www.xpdfreader.com/'
arch=('loong64' 'x86_64')
license=('GPL3')
backup=('etc/xpdfrc')
depends=('gsfonts' 'xdg-utils' 'qt5-base' 'libxt' 'libpaper' 'freetype2'
         'libcups' 'libjpeg-turbo' 'libtiff' 'libpng' 'zlib' 'qt5-svg'
         libfreetype.so libfontconfig.so)
optdepends=('poppler: tools that used to be included in xpdf'
            'desktop-file-utils: for desktop environments')
makedepends=('cmake' 'qt5-tools')
source=(https://dl.xpdfreader.com/xpdf-${pkgver}.tar.gz{,.sig}
        xpdf-4.00-permissions.patch
        xpdf-4.00-xpdfrc.patch
        xpdf.desktop)
sha512sums=('a26b67a4b3d5a5a365153845bf72d77949e683ce26aaf4705b49194cb32bbc581617c3e9c37f74bf6c49480df06d49e8c38d41233966b6215eacf92591d4d9bf'
            'SKIP'
            'f17c1c19c29518a3538a202c19fb60efc7721a42065d32c841f9ed929e571d9373c8558fdae251c1ef3781857cf51483244276179862998f94c9c1fd8bd63695'
            'c5ce8ef29d9b338fe3623fa52904d4fee5d76a34145614d05abe168108579608f3d16d0d03d34865e43980eb1b2a814f07aa3dbcfc0da06de34bd9b0738eef67'
            'd6163eb220bd567226c6006bef30c6db1eac1263ae161392db9766dca1ce78014cc555dd9d27febd2b924150053fa01b47c06777b1e760864459574c7614bfc4')
validpgpkeys=('A56006CA75CF8B13FA2F120DF4825F5397271342') # -Xpdf- <xpdf@xpdfreader.com>

prepare() {
  cd ${pkgname}-${pkgver}
  cp doc/sample-xpdfrc xpdfrc
  patch -Np1 < ../xpdf-4.00-permissions.patch
  patch -Np1 < ../xpdf-4.00-xpdfrc.patch
  sed 's:/usr/share/fonts/type1/gsfonts:/usr/share/fonts/Type1:' -i xpdf/GlobalParams.cc
}

build() {
  cd ${pkgname}-${pkgver}
  cmake .. \
    -DMULTITHREADED=ON \
    -DOPI_SUPPORT=ON \
    -DXPDFWIDGET_PRINTING=ON \
    -DSYSTEM_XPDFRC=/etc/xpdfrc \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -Wno-dev \
    -B build \
    -S .
  make -C build
}

package() {
  cd ${pkgname}-${pkgver}

  make -C build DESTDIR="${pkgdir}" install

  install -Dm 644 xpdfrc -t "${pkgdir}/etc"
  install -Dm 644 "${srcdir}/xpdf.desktop" -t "${pkgdir}/usr/share/applications"
  install -Dm 644 xpdf-qt/xpdf-icon.svg "${pkgdir}/usr/share/pixmaps/xpdf.svg"
  install -Dm 644 README CHANGES -t "${pkgdir}/usr/share/doc/${pkgname}"

  # remove stuff provided by poppler
  for tool in pdfdetach pdffonts pdfimages pdfinfo pdftoppm pdftops pdftotext pdftohtml; do
    rm "${pkgdir}/usr/bin/${tool}" "${pkgdir}/usr/share/man/man1/${tool}.1"
  done
}

# vim: ts=2 sw=2 et:
